package priv.pront.code.robot;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-07-28 14:22
 */
public class B3626_跳跃机器人 {

    static int n;
    static int[] dp;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        dp = new int[n + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = -1;
        dp[1] = 0;
        for (int i = 1; i <= n; i++) {
            if (i - 1 > 0) {
                dp[i] = Math.min(dp[i], dp[i - 1] + 1);
            }
            if (i + 1 <= n && dp[i + 1] != Integer.MAX_VALUE) {
                dp[i] = Math.min(dp[i], dp[i + 1] + 1);
            }
            if (2 * i <= n && dp[2 * i] != Integer.MAX_VALUE) {
                dp[i] = Math.min(dp[i], dp[2 * i] + 1);
            }
            if (i - 1 > 0) {
                dp[i - 1] = Math.min(dp[i - 1], dp[i] + 1);
            }
            if (i + 1 <= n) {
                dp[i + 1] = Math.min(dp[i + 1], dp[i] + 1);
            }
            if (2 * i <= n) {
                dp[2 * i] = Math.min(dp[2 * i], dp[i] + 1);
            }
        }
        System.out.println(dp[n]);

    }
}
